package com.iou.bean;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
 * Note class. ORM between the program and the DB is done using ORMLite.
 * 
 */
@DatabaseTable(tableName = "notes")
public class IOUNote {

    // Class variables, required info for the IOU-notes.
    @DatabaseField(generatedId = true)
    private Integer id;
    @DatabaseField
    private String type;
    @DatabaseField
    private double amount;
    @DatabaseField
    private String participant;
    @DatabaseField
    private String date;
    @DatabaseField
    private String description;
    @DatabaseField(foreign = true, foreignAutoRefresh = true)
    private IOUUser user;
    @DatabaseField
    private boolean status;
    @DatabaseField
    private Integer day;
    @DatabaseField
    private Integer month;
    @DatabaseField
    private Integer year;

    /**
     * Default constructor.
     */
    public IOUNote() {
        type = "";
        amount = 0;
        participant = "";
        date = "";
        description = "";
        status = false;
    }

    /**
     * Constructor.
     * 
     * @param type
     * @param amount
     * @param participant
     * @param description
     * @param day
     * @param month
     * @param year
     * @param status
     */
    public IOUNote(String type, double amount, String participant,
            String description, int day, int month, int year, boolean status) {
        this.type = type;
        this.amount = amount;
        this.participant = participant;
        this.date = day + "." + month + "." + year;
        this.description = description;
        this.status = status;
        this.day = day;
        this.month = month;
        this.year = year;
    }

    /**
     * 
     * @return
     */
    public double getAmount() {
        return amount;
    }

    /**
     * 
     * @return
     */
    public String getType() {
        return type;
    }

    /**
     * 
     * @param type
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * 
     * @param id
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * 
     * @param amount
     */
    public void setAmount(double amount) {
        this.amount = amount;
    }

    /**
     * 
     * @return
     */
    public String getParticipant() {
        return participant;
    }

    /**
     * 
     * @param participant
     */
    public void setParticipant(String participant) {
        this.participant = participant;
    }

    /**
     * 
     * @return
     */
    public boolean getStatus() {
        return status;
    }

    /**
     * 
     * @param status
     */
    public void setStatus(boolean status) {
        this.status = status;
    }

    /**
     * 
     * @return
     */
    public String getDate() {
        return date;
    }

    /**
     * 
     * @param date
     */
    public void setDate(String date) {
        this.date = date;
    }

    /**
     * 
     * @return
     */
    public String getDescription() {
        return description;
    }

    /**
     * 
     * @param description
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * 
     * @return
     */
    public int getId() {
        return id;
    }

    /**
     * 
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * 
     * @return
     */
    public IOUUser getUser() {
        return user;
    }

    /**
     * 
     * @param user
     */
    public void setUser(IOUUser user) {
        this.user = user;
    }

    /**
     * 
     * @return
     */
    public int getDay() {
        return day;
    }

    /**
     * 
     * @return
     */
    public int getMonth() {
        return month;
    }

    /**
     * 
     * @return
     */
    public int getYear() {
        return year;
    }

    /**
     * 
     * @return
     */
    public String getStatusString() {
        if (status) {
            return "Completed";
        } else {
            return "Not completed";
        }

    }

    @Override
    public String toString() {
        String username;
        if (this.getUser() != null) {
            username = user.getUsername();
        } else {
            username = "";
        }
        return getId() + " | " + getType() + " | " + getAmount() + " | "
                + getParticipant() + " | " + getDate() + " | "
                + getDescription() + " | " + username;
    }
}
